package jay.database;

import java.util.ArrayList;
import java.util.List;



import Database.LisDatabase;
import DatabaseHelper.LisMocDatabase;
import DatabaseHelper.ListMocDTO;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class DatabaseActivity extends Activity {
    /** Called when the activity is first created. */

	List<ListMocDTO> listItems = null;
	ListMocDTO newItem = null;
	private LisDatabase datasource;
	TextView t1 ;
	Button b1,b2;
	ListMocDTO listmoc;
	private SQLiteDatabase database;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        datasource = new LisDatabase(this);
		
		
	
    }
    public void Inse(View v)
    {
    	
    	EditText e1,e2;
    	e1=(EditText)findViewById(R.id.e1);
    	String tenfile=e1.getText().toString();
    	e2=(EditText)findViewById(R.id.e2);
    	String tentitle=e2.getText().toString();
    	CheckBox c1;
    	c1=(CheckBox)findViewById(R.id.checkBox1);
    	if(c1.isChecked()==true)// Chọn đánh dấu là = 1
    	{
    		Toast.makeText(this, "Check = 1", Toast.LENGTH_SHORT).show();
    	}
    	 ListMocDTO listFile = new ListMocDTO(tentitle, tenfile, c1.isChecked());
    	datasource.open();
		if(datasource.createRecord(listFile)){
			Toast.makeText(this, "Luu ban ghi thanh cong", Toast.LENGTH_SHORT).show();
		}
		datasource.close();
    }
    	public void Viewon(View v)
    	{
    		
//    		String sql =LisMocDatabase.COLUMN_ISDEFAULT + " = " + "1";
//    		Cursor cursor = database.query(LisMocDatabase.TABLE_NAME,
//    				null, null, null, null, null, null);
//    		startManagingCursor(cursor);
    		
    		// Make sure to close the cursor
//    		EditText e1,e2;
//        	e1=(EditText)findViewById(R.id.e1);
//        	String tenfile=e1.getText().toString();
//        	e2=(EditText)findViewById(R.id.e2);
//        	String tentitle=e2.getText().toString();
//        	CheckBox c1;
    		listItems = new ArrayList<ListMocDTO>();
    		datasource.open();
    		listItems = datasource.getAllRecords();
    		String ten="";
    		for(ListMocDTO t:listItems){
    			ten+= t.getFileName()+ " - " +t.getTitle() + " - " + ((t.getCheck()==true)?"1":"0") +" \n ";
    			
    		}
    	
    		t1=(TextView)findViewById(R.id.t2);
    		t1.setText(ten);
    		
   		
    		
    		
    	}
    	
   }
